#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<linux/input.h>

int main(int argc, const char **argv)
{
    int fd = -1;
    struct input_event evt;
    if(argc < 2)
    {
        printf("Argument is not enough\n");
        return 1;
    }

    fd = open(argv[1], O_RDONLY);
    if(fd < 0)
    {
        perror("open");
        return 2;
    }

    while(1)
    {
        read(fd, &evt, sizeof(evt));
        if(evt.type == EV_ABS)
        {
            switch (evt.code)
            {
            case ABS_X:
                printf("accel-x:%d\n", evt.value);
                break;
            case ABS_Y:
                printf("accel-y:%d\n", evt.value);
                break;
            case ABS_Z:
                printf("accel-z:%d\n", evt.value);
                break;
            case ABS_RX:
                printf("gyro-x:%d\n", evt.value);
                break;
            case ABS_RY:
                printf("gyro-y:%d\n", evt.value);
                break;
            case ABS_RZ:
                printf("gyro-z:%d\n", evt.value);
                break;
            case ABS_MISC:
                printf("temp:%d\n", evt.value);
                break;
            
            default:
                break;
            }
        }
    }

    close(fd);
    fd = -1;

    return 0;
}